package com.mz.mattress.client.api.biz;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mz.mattress.api.common.Result;
import com.mz.mattress.api.entity.MemberCard;
import com.mz.mattress.api.jwt.ClientJwt;
import com.mz.mattress.client.api.req.MemberCardReq;
import com.mz.mattress.client.common.Holder;
import com.mz.mattress.client.service.MemberCardService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Slf4j
@RestController
@RequestMapping("memberCard")
public class MemberCardController {

    @Autowired
    private MemberCardService memberCardService;

    @GetMapping("/listPage")
    public Result<IPage<MemberCard>> listPage(MemberCardReq req) {
        ClientJwt clientJwt = Holder.CLIENT_JWT_THREAD_LOCAL.get();
        req.setMemberId(clientJwt.getMemberId());
        return memberCardService.listPage(req);
    }

    @GetMapping("/list/{orderId}")
    public Result list(@PathVariable String orderId) {
        return memberCardService.list(Long.valueOf(orderId));
    }

    @GetMapping("/{id}")
    public Result<MemberCard> detail(@PathVariable Integer id) {
        return memberCardService.getById(id);
    }

//    @GetMapping("/send/{id}")
//    public Result send(@PathVariable Integer id) {
//
//        ClientJwt clientJwt = Holder.CLIENT_JWT_THREAD_LOCAL.get();
//        Long memberId = clientJwt.getMemberId();
//        return memberCardService.sendCard(id, memberId);
//    }

    @GetMapping("/check/{id}")
    public Result check(@PathVariable Integer id) {

        ClientJwt clientJwt = Holder.CLIENT_JWT_THREAD_LOCAL.get();
        Long memberId = clientJwt.getMemberId();
        return memberCardService.check(id, memberId);
    }

}
